package com.eleadmin.common.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eleadmin.common.system.mapper.HomestayMapper;
import com.eleadmin.common.system.service.HomestayService;
import com.eleadmin.common.system.entity.Homestay;
import com.eleadmin.common.system.param.HomestayParam;
import com.eleadmin.common.core.web.PageParam;
import com.eleadmin.common.core.web.PageResult;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Service实现
 *
 * @author EleAdmin
 * @since 2024-03-01 22:02:39
 */
@Service
public class HomestayServiceImpl extends ServiceImpl<HomestayMapper, Homestay> implements HomestayService {

    @Override
    public PageResult<Homestay> pageRel(HomestayParam param) {
        PageParam<Homestay, HomestayParam> page = new PageParam<>(param);
        //page.setDefaultOrder("create_time desc");
        List<Homestay> list = baseMapper.selectPageRel(page, param);
        return new PageResult<>(list, page.getTotal());
    }

    @Override
    public List<Homestay> listRel(HomestayParam param) {
        List<Homestay> list = baseMapper.selectListRel(param);
        // 排序
        PageParam<Homestay, HomestayParam> page = new PageParam<>();
        //page.setDefaultOrder("create_time desc");
        return page.sortRecords(list);
    }

    @Override
    public Homestay getByIdRel(Integer id) {
        HomestayParam param = new HomestayParam();
        param.setId(id);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
